package com.leetcode.No0231;

import org.junit.Test;

import java.util.ArrayList;

/**
 * @program: leetcode
 * @description:
 * @author: wangzhihua
 * @date: 2021-05-31
 */
public class Solution {

	public boolean isPowerOfTwo1(int n) {
		int[] nums = new int[]{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
		for (int num : nums) {
			if (num == n) {
				return true;
			}
		}
		return false;
	}

	public boolean isPowerOfTwo2(int n) {
		return n > 0 && (n & (-n)) == n;
	}

	public boolean isPowerOfTwo3(int n) {
		return n > 0 && (n & (n-1)) == 0;
	}

	@Test
	public void test01() {
		System.out.println(isPowerOfTwo3(5));
	}

	public static void main(String[] args) {
		int num = 1;
		ArrayList<Integer> nums = new ArrayList<Integer>();
		nums.add(num);
		while(num > 0) {
			num *= 2;
			nums.add(num);
		}
		System.out.print("{");
		for (Integer n : nums) {
			System.out.print(n + ", ");
		}
		System.out.println("}");
	}

}
